<template>
  <div class="goodBrandContainer">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>商品品牌管理</span>
      </div>
      <el-table
        :cell-style="{textAlign:'center'}"
        :data="goodBrandData"
        :header-cell-style="{textAlign:'center'}"
        style="width: 100%"
      >
        <el-table-column
          label="图片"
          prop="image"
        >
          <template slot-scope="scope">
            <el-popover placement="right" title="" trigger="click">
              <img :src="scope.row.image"  style="height: 200px;width: 200px"/>
              <img slot="reference" :src="scope.row.image" :alt="scope.row.image" style="height: 50px;width: 50px">
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column
          label="品牌名称"
          prop="name"
        />
        <el-table-column
          label="进口/国产"
          prop="type"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.type === 1 ? '国产' : '进口' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" :render-header="renderHeader">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" @click="edit(scope.row)">编辑</el-button>
            <el-button type="danger" size="mini" @click="del(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        style="margin: 20px 0;float: right"
        v-show="queryParams.total>0"
        :total="queryParams.total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getData"
      />
    </el-card>
  </div>
</template>

<script>

import { addBranList, delBranList, editBranList, getBranPage, queryBranList } from '@/api/goodBrand'

export default {
  name: 'GoodBrand',
  data() {
    return {
      //分页查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        total:0
      },
      goodBrandData: [],
      id:""
    }
  },
  created() {
    this.getData()
  },
  methods: {
    //获取商品品牌数据
    getData() {
      getBranPage().then(res => {
        this.goodBrandData=res.data.records
        this.queryParams.total=res.data.total
      })
    },
    renderHeader(h) {
      return (
        <div>操作
          <el-button type="success" size="mini" onClick={() => this.handleAddItem()} style="margin-left:20px"
          >添加</el-button>
        </div>
      )
    },
    //添加商品品牌信息
    handleAddItem() {
      //跳转到添加商品品牌页面
      this.$router.push('/addGoodBrand')
    },
  //  跳转到编辑商品品牌页面
    edit(row){
     this.$router.push({
       name:"editGoodBrand",
       query:{
         id:row.id
       }
     })
    },
  //  删除商品品牌信息
    del(row){
      const id=row.id
      this.$confirm('您确定删除这条数据么？','提示',{
        confirmButtonText:"确定",
        cancelButtonText:"取消",
        type:"warning"
      }).then(()=>{
        return delBranList(id).then(()=>{
          this.$message.success('删除成功')
          this.getData()
        })
      }).catch(()=>{})
    }
  },
}
</script>

<style scoped lang="scss">
.goodBrandContainer {
  padding: 20px;
}
</style>
